package org.yxt.springclod.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yxt.springclod.service.PaymentHystrixService;
import org.yxt.springcloud.entities.CommonResult;

import javax.annotation.Resource;

/**
 * hystrix使用
 *
 * @author Yang douya
 * @date 2022-01-03
 */
@RestController
@RequestMapping(value = "payment")
public class PaymentHystrixController {

    @Resource
    private PaymentHystrixService paymentHystrixService;

    /**
     * 正常操作暴露接口
     *
     * @param id
     * @return
     */
    @GetMapping(value = "hystrix/ok/{id}")
    public CommonResult ok(@PathVariable int id) {
        return paymentHystrixService.getOk(id);
    }

    /**
     * 异常操作暴露接口
     *
     * @param id
     * @return
     */
    @GetMapping(value = "hystrix/fail/{id}")
    public CommonResult fail(@PathVariable int id) {
        return paymentHystrixService.getFail(id);
    }

    /**
     * 服务熔断
     *
     * @param id
     * @return
     */
    @GetMapping(value = "hystrix/circuitBreaker/{id}")
    public CommonResult circuitBreaker(@PathVariable("id") int id) {
        return paymentHystrixService.circuitBreaker(id);
    }
}
